<template>
  <div class="app">
    <h3>我是App组件 ---- {{ car }}</h3>
    <Child />
  </div>
</template>

<script>
import { provide, reactive } from "vue";
import Child from "./components/Child.vue";
export default {
  name: "App",
  components: {
    Child,
  },
  setup() {
    let car = reactive({
      name: "奔驰",
      price: "40W",
    });

   /**
    * 作用：实现祖与后代组件间通信
      套路：父组件有一个 provide 选项来提供数据，后代组件有一个 inject 选项来开始使用这些数据
    */
    provide("car", car);

    return {
      car
    };
  },
};
</script>

<style>
.app {
  width: 800px;
  margin: 100px auto;
  background-color: gray;
  padding: 20px;
}
</style>
